﻿using System.Data;

namespace DAL
{
    public static class DalMail
    {
        private static readonly clsConnect Cls = new clsConnect();
        #region[Get-Data]
        public static DataTable GetMail(string keywords)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@KEYWORDS", keywords);
            return Cls.GetData("sp_Mail_Get");
        }
        public static DataTable GetMailEdit(int id)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", id);
            return Cls.GetData("sp_Mail_Get_Edit");
        }
        #endregion

        #region[Insert-Update-Delete]
        public static bool Insert(EtMail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@Email", obj.Email);
            Cls.AddParameter("@Passwords", obj.Passwords);
            Cls.AddParameter("@Port", obj.Port);
            Cls.AddParameter("@Host", obj.Host);
            Cls.AddParameter("@Content", obj.Content);
            Cls.AddParameter("@Subjects", obj.Subjects);
            Cls.AddParameter("@IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_Mail_Get_Insert");
        }
        public static bool Update(EtMail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", obj.ID);
            Cls.AddParameter("@Email", obj.Email);
            Cls.AddParameter("@Passwords", obj.Passwords);
            Cls.AddParameter("@Port", obj.Port);
            Cls.AddParameter("@Host", obj.Host);
            Cls.AddParameter("@Content", obj.Content);
            Cls.AddParameter("@Subjects", obj.Subjects);
            Cls.AddParameter("@IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_Mail_Get_Update");
        }
        public static bool UpdateNotPass(EtMail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", obj.ID);
            Cls.AddParameter("@Email", obj.Email);
            Cls.AddParameter("@Port", obj.Port);
            Cls.AddParameter("@Host", obj.Host);
            Cls.AddParameter("@Content", obj.Content);
            Cls.AddParameter("@Subjects", obj.Subjects);
            Cls.AddParameter("@IsActive", obj.IsActive);
            return Cls.ExecuteNonQuery("sp_Mail_Get_Update_NotPass");
        }
        public static bool Delete(EtMail obj)
        {
            Cls.CreateNewSqlCommand();
            Cls.AddParameter("@ID", obj.ID);
            return Cls.ExecuteNonQuery("sp_Mail_Get_Delete");
        }
        #endregion
    }
    public class EtMail
    {
        public int ID { get; set; }
        public string Email { get; set; }
        public string Passwords { get; set; }
        public int Port { get; set; }
        public string Host { get; set; }
        public string Content { get; set; }
        public string Subjects { get; set; }
        public bool IsActive { get; set; }
    }
}